package itheima05;

import java.util.*;
import java.util.stream.Stream;

/*
    获取Stream流的方式
    java.util.stream.Stream<T> 是Java 8新加入的最常用的流 接口

    1.方式一:                  -----------------掌握----------------
        java.util.Collection<T> 接口
        默认方法: 必须由Collection接口的实现类(ArrayList/LinkedList/HashSet/LinkedHashSet)对象调用
            public default Stream<T> stream(): 获取Collection集合对象对应的Stream流对象

    2.方式二:
        java.util.stream.Stream<T> 接口:
        静态方法
        public static <T> Stream<T> of(T ... t): 把方法的可变参数指定的具体数据,转换成Stream流对象
            参数:
                T ... t: 可变参数   传递数组,参数列表,不传递
 */
public class Demo05GetStream {
    public static void main(String[] args) {
        //获取List集合的Stream对象
        List<String> list = new ArrayList<>();
        Stream<String> s1 = list.stream();
        System.out.println(s1);

        //获取Set集合的Stream对象
        Set<Integer> set = new HashSet<>();
        Stream<Integer> s2 = set.stream();
        System.out.println(s2);

        Map<String,String> map = new HashMap<>();

        //Map键的Set集合
        Set<String> set2 = map.keySet();
        Stream<String> s3 = set2.stream();
        System.out.println(s3);

        //Map值的Collection集合
        Collection<String> coll = map.values();
        Stream<String> s4 = coll.stream();
        System.out.println(s4);

        //Map键值对的Set集合
        Set<Map.Entry<String, String>> set3 = map.entrySet();
        Stream<Map.Entry<String, String>> s5 = set3.stream();
        System.out.println(s5);
        System.out.println("----------");
        String[] arr = {"Hello","World","java"};
        Stream<String> s6 = Stream.of(arr);
        System.out.println(s6);

        Stream<String> s7 = Stream.of("Hello", "World", "java");
        System.out.println(s7);

    }
}
